const Response = require('../utils/response');
const statisticsService = require('../services/statisticsService');

class StatisticsController {
  // 获取总体统计数据
  async getStatistics(req, res) {
    try {
      const stats = await statisticsService.getStatistics();
      res.json(Response.success(stats));
    } catch (error) {
      res.json(Response.error(error.message));
    }
  }

  // 获取用户统计
  async getUserStatistics(req, res) {
    try {
      const stats = await statisticsService.getUserStatistics();
      res.json(Response.success(stats));
    } catch (error) {
      res.json(Response.error(error.message));
    }
  }

  // 获取书籍统计
  async getBookStatistics(req, res) {
    try {
      const stats = await statisticsService.getBookStatistics();
      res.json(Response.success(stats));
    } catch (error) {
      res.json(Response.error(error.message));
    }
  }

  // 获取互动统计
  async getInteractionStatistics(req, res) {
    try {
      const stats = await statisticsService.getInteractionStatistics();
      res.json(Response.success(stats));
    } catch (error) {
      res.json(Response.error(error.message));
    }
  }

  // 获取时间段统计
  async getPeriodStatistics(req, res) {
    try {
      const { startDate, endDate } = req.query;
      const stats = await statisticsService.getPeriodStatistics(startDate, endDate);
      res.json(Response.success(stats));
    } catch (error) {
      res.json(Response.error(error.message));
    }
  }
}

module.exports = new StatisticsController(); 